package com.bigwork.dto.order;

import com.bigwork.entity.OrderItem;
import com.bigwork.entity.Product;
import lombok.Data;
import java.math.BigDecimal;

@Data
public class OrderItemResponse {
    private Long productId;
    private String productName;
    private Integer quantity;
    private BigDecimal price;

    public static OrderItemResponse fromEntity(OrderItem orderItem) {
        OrderItemResponse dto = new OrderItemResponse();
        Product product = orderItem.getProduct();
        if (product != null) {
            dto.setProductId(product.getId());
            dto.setProductName(product.getName());
        }
        dto.setQuantity(orderItem.getQuantity());
        dto.setPrice(orderItem.getPrice());
        return dto;
    }
}